﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace USBControlLib
{
    /// <summary>
    /// 通短板控制动态库C++接口声明
    /// </summary>
    public static class ControlLib
    {       
        private const string strDllFile = "USBControl.dll";

        /// <summary>
        /// 获取动态库版本
        /// </summary>
        /// <param name="Version">返回的具体版本信息，由调用者申请空间。</param>
        /// <param name="length">调用者所申请的 cVersion 空间大小</param>
        /// <returns></returns>
        [DllImport(strDllFile, CallingConvention = CallingConvention.StdCall, EntryPoint = "BoardGetDllVersionControl")]
        public static extern int BoardGetDllVersionControl(ref byte str, ref int bufferLen);

        /// <summary>
        /// 获取动态库版本
        /// </summary>
        /// <param name="Version">返回的具体版本信息，由调用者申请空间。</param>
        /// <param name="length">调用者所申请的 cVersion 空间大小</param>
        /// <returns></returns>
        [DllImport(strDllFile, CallingConvention = CallingConvention.StdCall, EntryPoint = "BoardGetDllVersionControl", CharSet = CharSet.Auto)]
        public static extern int BoardGetDllVersionControl([Out, MarshalAs(UnmanagedType.LPStr)] StringBuilder builder, ref int bufferLen);

        /// <summary>
        /// 初始化动态库
        /// </summary>
        /// <param name="m_hWnd">：窗口句柄，用于异步执行时发送消息</param>
        /// <param name="msg">消息代码，用于异步执行时发送消息</param>
        /// <param name="cfgFile">配置文件 包括路径 Null ：时读取本地 EmpMachine.ini 配置文件；</param>
        /// <returns></returns>
        [DllImport(strDllFile, CallingConvention = CallingConvention.StdCall)]
        public static extern int BoardInitialCtrlDll(IntPtr m_hWnd, uint msg, string cfgFile);

        /// <summary>
        /// 卸载动态库
        /// </summary>
        /// <returns></returns>
        [DllImport(strDllFile, CallingConvention = CallingConvention.StdCall)]
        public static extern int BoardUnInitialCtrlDll();

        /// <summary>
        /// 通断 USB1 通道 （模拟人的插拔过程
        /// </summary>
        /// <returns></returns>
        [DllImport(strDllFile, CallingConvention = CallingConvention.StdCall)]
        public static extern int BoardControlChannel1();

        /// <summary>
        /// 查询USB1 通道通断流程结果
        /// </summary>
        /// <returns></returns>
        [DllImport(strDllFile, CallingConvention = CallingConvention.StdCall)]
        public static extern int BoardQueryChannel1();

        /// <summary>
        /// 通断USB2 通道（模拟人的插拔过程）
        /// </summary>
        /// <returns>0:成功 其它 错误代码</returns>
        [DllImport(strDllFile, CallingConvention = CallingConvention.StdCall)]
        public static extern int BoardControlChannel2();

        /// <summary>
        /// 查询USB2 通道通断流程结果
        /// </summary>
        /// <returns></returns>
        [DllImport(strDllFile, CallingConvention = CallingConvention.StdCall)]
        public static extern int BoardQueryChannel2();

        /// <summary>
        /// 通断 USB3 通道 （模拟人的插拔过程
        /// </summary>
        /// <returns></returns>
        [DllImport(strDllFile, CallingConvention = CallingConvention.StdCall)]
        public static extern int BoardControlChannel3();

        /// <summary>
        /// 查询USB3通道通断流程结果
        /// </summary>
        /// <returns></returns>
        [DllImport(strDllFile, CallingConvention = CallingConvention.StdCall)]
        public static extern int BoardQueryChannel3();

        /// <summary>
        /// 通断USB4 通道（模拟人的插拔过程）
        /// </summary>
        /// <returns>0:成功 其它 错误代码</returns>
        [DllImport(strDllFile, CallingConvention = CallingConvention.StdCall)]
        public static extern int BoardControlChannel4();

        /// <summary>
        /// 查询USB4 通道通断流程结果
        /// </summary>
        /// <returns></returns>
        [DllImport(strDllFile, CallingConvention = CallingConvention.StdCall)]
        public static extern int BoardQueryChannel4();

        /// <summary>
        /// 通断 USB5 通道 （模拟人的插拔过程
        /// </summary>
        /// <returns></returns>
        [DllImport(strDllFile, CallingConvention = CallingConvention.StdCall)]
        public static extern int BoardControlChannel5();

        /// <summary>
        /// 查询USB5 通道通断流程结果
        /// </summary>
        /// <returns></returns>
        [DllImport(strDllFile, CallingConvention = CallingConvention.StdCall)]
        public static extern int BoardQueryChannel5();

        /// <summary>
        /// 通断USB6 通道（模拟人的插拔过程）
        /// </summary>
        /// <returns>0:成功 其它 错误代码</returns>
        [DllImport(strDllFile, CallingConvention = CallingConvention.StdCall)]
        public static extern int BoardControlChannel6();

        /// <summary>
        /// 查询USB6 通道通断流程结果
        /// </summary>
        /// <returns></returns>
        [DllImport(strDllFile, CallingConvention = CallingConvention.StdCall)]
        public static extern int BoardQueryChannel6();

        /// <summary>
        /// 通断 USB7 通道 （模拟人的插拔过程
        /// </summary>
        /// <returns></returns>
        [DllImport(strDllFile, CallingConvention = CallingConvention.StdCall)]
        public static extern int BoardControlChannel7();

        /// <summary>
        /// 查询USB7通道通断流程结果
        /// </summary>
        /// <returns></returns>
        [DllImport(strDllFile, CallingConvention = CallingConvention.StdCall)]
        public static extern int BoardQueryChannel7();

        /// <summary>
        /// 通断USB8 通道（模拟人的插拔过程）
        /// </summary>
        /// <returns>0:成功 其它 错误代码</returns>
        [DllImport(strDllFile, CallingConvention = CallingConvention.StdCall)]
        public static extern int BoardControlChannel8();

        /// <summary>
        /// 查询USB8通道通断流程结果
        /// </summary>
        /// <returns></returns>
        [DllImport(strDllFile, CallingConvention = CallingConvention.StdCall)]
        public static extern int BoardQueryChannel8();

        /// <summary>
        /// 接通选择的USB 通道
        /// </summary>
        /// <param name="channel">选择 1~ 8 通道</param>
        /// <returns>0:成功 其它 错误代码</returns>
        [DllImport(strDllFile, CallingConvention = CallingConvention.StdCall)]
        public static extern int BoardChannelConnect(int channel);

        /// <summary>
        /// 断开选择的USB 通道
        /// </summary>
        /// <param name="channel">：选择 1~8 通道</param>
        /// <returns></returns>
        [DllImport(strDllFile, CallingConvention = CallingConvention.StdCall)]
        public static extern int BoardChannelDisConnect(int channel);
    }
}
